
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>过去一周温度变化</title>
    <script src="../js/echarts.min.js"></script>
    <script src="../js/jquery.js"></script>
    <script>
        var times=[];
        var maxs=[];
        var mins=[];
    </script>
    <style>
        #main{
            text-align: center;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div id="main" style="width: 800px;height:600px;"></div>

<script>
    $.ajax({
        url:"/pxthadoop/temper",
        dataType:"json",
        type:"post",
        async:false,
        success:function (result) {
            /*var data = JSON.stringify(result);
            alert(data);*/
            $.each(result.data,function (i,v) {
                /* alert(v.time+":"+v.max+":"+v.min);*/
                times[i] = v.time;
                maxs[i] = parseInt(v.max);
                mins[i]=parseInt(v.min);

            })
        }
    })
    var myChart = echarts.init(document.getElementById('main'));

    var option = {
        title: {
            text: '过去一周气温变化',
            /*subtext: '纯属虚构'*/
        },
        tooltip: {
            trigger: 'axis'
        },

        legend: {
            data: ['最高气温', '最低气温']
        },

        toolbox: {
            show: true,
            feature: {
                dataZoom: {
                    yAxisIndex: 'none'
                },
                dataView: {readOnly: false},
                magicType: {type: ['line', 'bar']},
                restore: {},
                saveAsImage: {}
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: times
        },
        yAxis: {
            max: 50,
            type: 'value',
            minInterval: 0,
            interval: 10,//每次增加几个
            axisLabel: {
                formatter: '{value} °C'
            }
        },
        series: [
            {
                name: '最高气温',
                type: 'line',
                data: maxs,

            },
            {
                name: '最低气温',
                type: 'line',
                data: mins,

            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。

    option.series[0].max =60;
    myChart.setOption(option);

    //点击事件
    myChart.on('click',function (params) {
        console.log(params);
        var name = params.name;
        if (name==times[0]){
            window.location.href="firstday.jsp";
        }else if(name==times[1]){
            window.location.href="twoday.jsp";
        }else if(name==times[2]){

        }else if(name==times[3]){

        }else if(name==times[4]){

        }else if(name==times[5]){

        }else if(name==times[6]){

        }
    });
    myChart.on('click',eConsole);
</script>
</body>
</html>